#import <Foundation/Foundation.h>
#import <CoreFoundation/CoreFoundation.h>
#import "../LockboxStorage.h"
#import "../LockboxItem.h"
#import "../SSCrypto.h"
//#include <unistd.h>
//#include <sys/stat.h>

@interface StorageTests : NSObject

- (void)SimpleWriteTest;

@end

@implementation StorageTests

- (void)SimpleWriteTest
{

    int i;
    for (i = 0; i < 25; i++) {
        LockboxStorage* storage = [[LockboxStorage alloc] init];
        
        [storage loadDummyData];
        [storage changeKey:@"l33tpassword"];
        [storage release];
        
        storage = [[LockboxStorage alloc] init];
        [storage loadWithKey:@"l33tpassword"];
        
        NSMutableArray* items = [storage items];
        NSAssert([items count] == 3, @"Item count is not 3");
        
        LockboxItem* phylarPwItem = [items objectAtIndex:0];
        NSAssert1([phylarPwItem->key compare:@"Phylar"] == NSOrderedSame, 
            @"--==item 0 key isn't as expected: %@ ==--", phylarPwItem->value);
        NSAssert1([phylarPwItem->value compare:@"notmypassword"] == NSOrderedSame, 
            @"--==item 0 value isn't as expected: %@ ==--", phylarPwItem->value);

        LockboxItem* ssnItem = [items objectAtIndex:1];
        NSAssert1([ssnItem->value compare:@"123-45-6789"] == NSOrderedSame, 
            @"--==item 1 value isn't as expected: %@ ==--", ssnItem->value);
        
        LockboxItem* discoverItem = [items objectAtIndex:2];
        NSAssert1([discoverItem->phone1 compare:@"18003472683"] == NSOrderedSame, 
            @"--==item 2 phone1 isn't as expected: %@ ==--", discoverItem->value);
        
        [storage release];
    }
    NSLog(@"SimpleWriteTest passed\n");

}

@end

int main(int argc, char **argv)
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    
    StorageTests* tests = [[StorageTests alloc] init];
    [tests SimpleWriteTest];
    //CsvBasicTest();

    [pool release];
    
    return 0;
}
